package com.meiyu.live.ui.main.widget;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.meiyu.live.R;
import com.meiyu.live.popj.LiveRoom;
import com.meiyu.live.tv.audience.AudienceActivity;
import com.meiyu.live.util.BitmapHelp;

public class NowHotLiveDetailItemView extends FrameLayout implements View.OnClickListener {

    private TextView tv_name, tv_appoint_count, tv_content1, tv_content2;
    private ImageView iv_tv;
    private ProgressBar progressBar;

    private ImageLoader imageLoader;
    private DisplayImageOptions options;

    private LiveRoom bean;

    public NowHotLiveDetailItemView(Context context) {
        super(context);
        init(context);
    }

    public NowHotLiveDetailItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public NowHotLiveDetailItemView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init(context);
    }

    private void init(Context context) {
        LayoutInflater inflater = LayoutInflater.from(context);
        inflater.inflate(R.layout.adapter_nowhot_itemdetail, this);
        tv_name = (TextView) findViewById(R.id.tv_name);
        iv_tv = (ImageView) findViewById(R.id.iv_tv);
        tv_appoint_count = (TextView) findViewById(R.id.tv_appoint_count);
        tv_content1 = (TextView) findViewById(R.id.tv_content1);
        tv_content2 = (TextView) findViewById(R.id.tv_content2);
        iv_tv = (ImageView) findViewById(R.id.iv_tv);
        progressBar = (ProgressBar) findViewById(R.id.progressBar);
        setOnClickListener(this);
    }

    public void setImageLoader(ImageLoader imageLoader, DisplayImageOptions options) {
        this.imageLoader = imageLoader;
        this.options = options;
    }

    public void setData(LiveRoom bean) {
        this.bean = bean;
        tv_name.setText(bean.getAnchor_name());
        imageLoader.displayImage(BitmapHelp.getImgByCdn(bean.getAvatar(), "m_fill", "300", "300"), iv_tv, options);
        tv_appoint_count.setText(bean.getViewer_num() + "人正在观看");
        tv_content1.setText(TextUtils.isEmpty(bean.getDescription()) ? "无介绍" : bean.getDescription());
        progressBar.setVisibility(View.GONE);
        tv_content2.setVisibility(View.GONE);
    }

    @Override
    public void onClick(View view) {
        if (bean != null) {
            AudienceActivity.start(getContext(), bean);
        }
    }
}
